using System;
using Csla;
using System.Collections;
namespace Company.Business.Article
{
	[Serializable]
	public partial class ArticleImages : BusinessBase<ArticleImages>
	{

		#region Business Methods
		public static readonly PropertyInfo<int> ArtMpaiIdProperty = RegisterProperty<int>(c => c.ArtMpaiId);
		public int ArtMpaiId
		{
			get {return GetProperty(ArtMpaiIdProperty); }
			set {SetProperty(ArtMpaiIdProperty, value); }
		}

		public static readonly PropertyInfo<int> MparArtMparIdProperty = RegisterProperty<int>(c => c.MparArtMparId);
		public int MparArtMparId
		{
			get {return GetProperty(MparArtMparIdProperty); }
			set {SetProperty(MparArtMparIdProperty, value); }
		}

		public static readonly PropertyInfo<byte[]> ImgProperty = RegisterProperty<byte[]>(c => c.Img);
		public byte[] Img
		{
			get {return GetProperty(ImgProperty); }
			set {SetProperty(ImgProperty, value); }
		}

		public static readonly PropertyInfo<string> ComntProperty = RegisterProperty<string>(c => c.Comnt);
		public string Comnt
		{
			get {return GetProperty(ComntProperty); }
			set {SetProperty(ComntProperty, value); }
		}

		public static readonly PropertyInfo<int> SeqProperty = RegisterProperty<int>(c => c.Seq);
		public int Seq
		{
			get {return GetProperty(SeqProperty); }
			set {SetProperty(SeqProperty, value); }
		}

		public static readonly PropertyInfo<DateTime> InsDatProperty = RegisterProperty<DateTime>(c => c.InsDat);
		public DateTime InsDat
		{
			get {return GetProperty(InsDatProperty); }
			set {SetProperty(InsDatProperty, value); }
		}

		public static readonly PropertyInfo<string> InsOperProperty = RegisterProperty<string>(c => c.InsOper);
		public string InsOper
		{
			get {return GetProperty(InsOperProperty); }
			set {SetProperty(InsOperProperty, value); }
		}

		public static readonly PropertyInfo<DateTime> MutDatProperty = RegisterProperty<DateTime>(c => c.MutDat);
		public DateTime MutDat
		{
			get {return GetProperty(MutDatProperty); }
			set {SetProperty(MutDatProperty, value); }
		}

		public static readonly PropertyInfo<string> MutOperProperty = RegisterProperty<string>(c => c.MutOper);
		public string MutOper
		{
			get {return GetProperty(MutOperProperty); }
			set {SetProperty(MutOperProperty, value); }
		}

		public static readonly PropertyInfo<string> PimtPimtIdProperty = RegisterProperty<string>(c => c.PimtPimtId);
		public string PimtPimtId
		{
			get {return GetProperty(PimtPimtIdProperty); }
			set {SetProperty(PimtPimtIdProperty, value); }
		}

		public static readonly PropertyInfo<int> MpaiArtMpaiIdProperty = RegisterProperty<int>(c => c.MpaiArtMpaiId);
		public int MpaiArtMpaiId
		{
			get {return GetProperty(MpaiArtMpaiIdProperty); }
			set {SetProperty(MpaiArtMpaiIdProperty, value); }
		}

		protected override object GetIdValue()
		{
			return ArtMpaiId;
		}

		#endregion

		#region Business Rules
		protected override void AddBusinessRules()
		{
			base.AddBusinessRules();

			BusinessRules.AddRule(new Csla.Rules.CommonRules.Required(ArtMpaiIdProperty));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.Required(MparArtMparIdProperty));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.Required(ImgProperty));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.MaxLength(ComntProperty, 2000));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.Required(InsDatProperty));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.MaxLength(InsOperProperty, 15));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.Required(InsOperProperty));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.MaxLength(MutOperProperty, 15));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.MaxLength(PimtPimtIdProperty, 10));
		}

		#endregion

		#region Factory Methods
		internal static ArticleImages New()
		{
			var articleimages = DataPortal.CreateChild<ArticleImages>();
			return articleimages;
		}

		internal static ArticleImages Get(object fetchData)
		{
			return DataPortal.FetchChild<ArticleImages>(fetchData);
		}

		private ArticleImages()
		{
			/* Require use of factory methods */ 
		}

		#endregion

		#region Data Portal
		[RunLocal]
		protected override void Child_Create()
		{
			//load default values here
			//omit this override if you have no defaults to set
			base.DataPortal_Create();
		}

		// ReSharper disable UnusedMember.Local
		private void Child_Fetch(object fetchData)
		// ReSharper restore UnusedMember.Local
		{
			using (BypassPropertyChecks)
			{
				//Stub: Write fetchdata to the CSLA Object 
				//LoadProperty(ArtMpaiIdProperty, ???ArtMpaiId);
				//LoadProperty(MparArtMparIdProperty, ???MparArtMparId);
				//LoadProperty(ImgProperty, ???Img);
				//LoadProperty(ComntProperty, ???Comnt);
				//LoadProperty(SeqProperty, ???Seq);
				//LoadProperty(InsDatProperty, ???InsDat);
				//LoadProperty(InsOperProperty, ???InsOper);
				//LoadProperty(MutDatProperty, ???MutDat);
				//LoadProperty(MutOperProperty, ???MutOper);
				//LoadProperty(PimtPimtIdProperty, ???PimtPimtId);
				//LoadProperty(MpaiArtMpaiIdProperty, ???MpaiArtMpaiId);
			}

		}

		 [Transactional(TransactionalTypes.TransactionScope)]
		// ReSharper disable UnusedMember.Local
		// ReSharper disable UnusedParameter.Local
		private void Child_Insert(object parent)
		// ReSharper restore UnusedParameter.Local
		// ReSharper restore UnusedMember.Local
		{
			using (BypassPropertyChecks)
			{
				//Stub: Write Data to a new DB Object
				//dbObject.ArtMpaiId = ArtMpaiId;
				//dbObject.MparArtMparId = MparArtMparId;
				//dbObject.Img = Img;
				//dbObject.Comnt = Comnt;
				//dbObject.Seq = Seq;
				//dbObject.InsDat = InsDat;
				//dbObject.InsOper = InsOper;
				//dbObject.MutDat = MutDat;
				//dbObject.MutOper = MutOper;
				//dbObject.PimtPimtId = PimtPimtId;
				//dbObject.MpaiArtMpaiId = MpaiArtMpaiId;
				//dbObject.Save();
			}

			FieldManager.UpdateChildren(this);
		}

		// ReSharper disable UnusedMember.Local
		 [Transactional(TransactionalTypes.TransactionScope)]
		private void Child_Update(object parent)
		// ReSharper restore UnusedMember.Local
		{
			if (IsSelfDirty)
			{
				using (BypassPropertyChecks)
				{
					//Stub: Write Data to the corresponding DB Object
					//dbObject.ArtMpaiId = ArtMpaiId;
					//dbObject.MparArtMparId = MparArtMparId;
					//dbObject.Img = Img;
					//dbObject.Comnt = Comnt;
					//dbObject.Seq = Seq;
					//dbObject.InsDat = InsDat;
					//dbObject.InsOper = InsOper;
					//dbObject.MutDat = MutDat;
					//dbObject.MutOper = MutOper;
					//dbObject.PimtPimtId = PimtPimtId;
					//dbObject.MpaiArtMpaiId = MpaiArtMpaiId;
					//dbObject.Save();
				}

			}

			FieldManager.UpdateChildren(this);
		}

		 [Transactional(TransactionalTypes.TransactionScope)]
		// ReSharper disable UnusedMember.Local
		private void Child_DeleteSelf(object parent)
		// ReSharper restore UnusedMember.Local
		{
			//Stub: Delete the corresponding DB Object
			ArtMpaiId=0;
		}

		#endregion
	}

}

